#ifndef REQUEST_HANDLER_CLIENT_HH
# define REQUEST_HANDLER_CLIENT_HH

# include <request/request-handler.hh>
# include <network/network-manager.hh>
# include <set>

# include <tbb/concurrent_hash_map.h>

# include "../action/action_queue.hh"
# include "../display/object.hh"
# include "../map/map.hh"

class Server;

class RequestHandlerClient: public RequestHandler
{
public:
  RequestHandlerClient (tbb::concurrent_hash_map<int, boost::shared_ptr<Object> >* objmap,
			tbb::concurrent_hash_map<int, boost::shared_ptr<Displayable> >* disp,
			NetworkManager& nm);

  virtual void treat (const boost::shared_ptr<GetObject>& o, const int* clientid = 0);
  virtual void treat (const boost::shared_ptr<AskMap>& o, const int* clientid = 0);
  virtual void treat (const boost::shared_ptr<Connection>& o, const int* clientid = 0);
  virtual void treat (const boost::shared_ptr<Disconnection>& o, const int* clientid = 0);
  virtual void treat (const boost::shared_ptr<GetAllObjects>& o, const int* clientid = 0);
  virtual void treat (const boost::shared_ptr<Text>& o, const int* clientid = 0);
  virtual void treat (const boost::shared_ptr<UpdateObj>& o, const int* clientid = 0);
  virtual void treat (const boost::shared_ptr<UpdatePos>& o, const int* clientid = 0);
  virtual void treat (const boost::shared_ptr<GameMode>& o, const int* clientid = 0);
  virtual void treat (const boost::shared_ptr<GameZone>& o, const int* clientid = 0);
  virtual void treat (const boost::shared_ptr<Ready>& o, const int* clientid = 0);
  virtual void treat (const boost::shared_ptr<Move>& o, const int* clientid = 0);

  Map* rts_map () const { return rts_map_; }
  Map* fps_map () const { return (!fps_map_ok_? 0: fps_map_); }

protected:
  tbb::concurrent_hash_map<int, boost::shared_ptr<Object> >* objmap_;
  tbb::concurrent_hash_map<int, boost::shared_ptr<Displayable> >* disp_;

  void build_map_rts ();
  void build_map_fps ();

  Map* rts_map_;

  Map* fps_map_;
  bool fps_map_ok_;

  NetworkManager& nm_;
  std::queue<Action*>* queue_;
  std::set<int> waitingobj_;
};

#endif /// !REQUEST_HANDLER_CLIENT_HH
